<template>
  <div class="tab-control">
   <div v-for="(item,index) in title"  class="tab-control-item"
   :class="{chose: index ===  currentIndex}"  @click="changeIndex(index)">
    <span>{{item}}</span>
   </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: {
    title:{
      type: Array,
      default(){
        return []
      }
    }
  },
  data(){
    return {
      currentIndex: 0
    }
  },
  methods:{
    // 这里已经传入了index
    changeIndex(index){
      this.currentIndex = index
      this.$emit('tabClick', index)
    }
  }
}
</script>

<style scoped>
  .tab-control {
    display: flex;
    font-size: 16px;
    text-align: center;
    padding: 9px;
    background-color: #fff;
    z-index: 9;
  }
  .tab-control-item{
    flex: 1;
  }
  .chose{
    color: orangered;
  }
  .chose span {
    padding-bottom: 3px;
    border-bottom: rgba(255, 65, 0, 0.56) solid 3px;
  }
</style>
